package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.activity.client.ActivityFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @Author: 李旭
 * @Time: 10:43
 * @Description:
 */
@Controller
public class SeckillController {

    @Autowired
    private ActivityFeignClient activityFeignClient;
    //秒杀频道页面  seckill.gmall.com
    @GetMapping("/index")
    public String secKillindex(Model model){


        List<SeckillGoods> all = activityFeignClient.findAll();
        model.addAttribute("list",all);
        return "seckill/index";
    }
    //秒杀详情页面
    @GetMapping("/seckill/{skuId}.html")
    public String seckillDetail(@PathVariable Long skuId,Model model){

        SeckillGoods seckillGoods = activityFeignClient.findBySkuId(skuId);
        model.addAttribute("item",seckillGoods);
        return "seckill/item";
    }

    //跳转抢购页面  页面里 VUE 钩子 调用开始抢购
    @GetMapping("/seckill/queue.html")
    public String queue(Long skuId,String skuIdStr,Model model){
        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }
}
